package 蓝桥杯.算法板子.图论;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * @Title: Floyd求最短路
 * @Author 贾金博
 * @Package 蓝桥杯.算法板子.图论
 * @Date 2024/4/12 21:56
 * @description:
 */
public class Floyd求最短路 {
    public static MyFastRead sc = new MyFastRead();
    public static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));


    public static void main(String[] args) {
        int n, m, k;
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        int[][] dis = new int[210][210];

        for(int i = 1; i <= n; ++ i ) {
            for(int j = 1; j <= n; ++ j ) {
                dis[i][j] = 0x3f3f3f3f;
            }
        }

        for(int i = 1; i <= n; ++ i ) {
            dis[i][i] = 0; // 自身到自身是0
        }

        for(int i = 1; i <= m; ++ i ) {
            int a, b, c;
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            dis[a][b] = Math.min(dis[a][b], c);
        }

        for(int i = 1; i <= n; ++ i ) {
            for(int j = 1; j <= n; ++ j ) {
                for(int p = 1; p <= n; ++ p ) {
                    dis[j][p] = Math.min(dis[j][p], dis[j][i] + dis[i][p]);
                }
            }
        }
        while(k -- != 0) {
            int x, y;
            x = sc.nextInt();
            y = sc.nextInt();
            if(dis[x][y] >= 0x3f3f3f / 2) {
                out.println("impossible");
            } else {
                out.println(dis[x][y]);
            }
        }
        out.flush();
    }
}
